{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 手写数字识别简单版本"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "from tensorflow.examples.tutorials.mnist import input_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Extracting MNIST_data\\train-images-idx3-ubyte.gz\n",
      "Extracting MNIST_data\\train-labels-idx1-ubyte.gz\n",
      "Extracting MNIST_data\\t10k-images-idx3-ubyte.gz\n",
      "Extracting MNIST_data\\t10k-labels-idx1-ubyte.gz\n",
      "Iter0, Testing Accuracy:0.7429\n",
      "Iter1, Testing Accuracy:0.8319\n",
      "Iter2, Testing Accuracy:0.8602\n",
      "Iter3, Testing Accuracy:0.871\n",
      "Iter4, Testing Accuracy:0.8773\n",
      "Iter5, Testing Accuracy:0.8819\n",
      "Iter6, Testing Accuracy:0.8849\n",
      "Iter7, Testing Accuracy:0.8881\n",
      "Iter8, Testing Accuracy:0.8914\n",
      "Iter9, Testing Accuracy:0.8945\n",
      "Iter10, Testing Accuracy:0.8955\n",
      "Iter11, Testing Accuracy:0.8974\n",
      "Iter12, Testing Accuracy:0.8982\n",
      "Iter13, Testing Accuracy:0.8989\n",
      "Iter14, Testing Accuracy:0.9007\n",
      "Iter15, Testing Accuracy:0.9022\n",
      "Iter16, Testing Accuracy:0.9027\n",
      "Iter17, Testing Accuracy:0.9034\n",
      "Iter18, Testing Accuracy:0.9042\n",
      "Iter19, Testing Accuracy:0.9054\n",
      "Iter20, Testing Accuracy:0.9061\n",
      "Iter21, Testing Accuracy:0.9061\n",
      "Iter22, Testing Accuracy:0.9066\n",
      "Iter23, Testing Accuracy:0.9073\n",
      "Iter24, Testing Accuracy:0.9074\n",
      "Iter25, Testing Accuracy:0.908\n",
      "Iter26, Testing Accuracy:0.9092\n",
      "Iter27, Testing Accuracy:0.9093\n",
      "Iter28, Testing Accuracy:0.91\n",
      "Iter29, Testing Accuracy:0.9102\n",
      "Iter30, Testing Accuracy:0.9099\n",
      "Iter31, Testing Accuracy:0.9107\n",
      "Iter32, Testing Accuracy:0.9112\n",
      "Iter33, Testing Accuracy:0.9113\n",
      "Iter34, Testing Accuracy:0.9117\n",
      "Iter35, Testing Accuracy:0.9121\n",
      "Iter36, Testing Accuracy:0.9128\n",
      "Iter37, Testing Accuracy:0.9136\n",
      "Iter38, Testing Accuracy:0.9132\n",
      "Iter39, Testing Accuracy:0.9137\n",
      "Iter40, Testing Accuracy:0.9142\n",
      "Iter41, Testing Accuracy:0.9141\n",
      "Iter42, Testing Accuracy:0.9139\n",
      "Iter43, Testing Accuracy:0.9145\n",
      "Iter44, Testing Accuracy:0.9146\n",
      "Iter45, Testing Accuracy:0.9148\n",
      "Iter46, Testing Accuracy:0.9153\n",
      "Iter47, Testing Accuracy:0.9152\n",
      "Iter48, Testing Accuracy:0.9156\n",
      "Iter49, Testing Accuracy:0.916\n",
      "Iter50, Testing Accuracy:0.9161\n",
      "Iter51, Testing Accuracy:0.916\n",
      "Iter52, Testing Accuracy:0.916\n",
      "Iter53, Testing Accuracy:0.9166\n",
      "Iter54, Testing Accuracy:0.9169\n",
      "Iter55, Testing Accuracy:0.9171\n",
      "Iter56, Testing Accuracy:0.9177\n",
      "Iter57, Testing Accuracy:0.9179\n",
      "Iter58, Testing Accuracy:0.9176\n",
      "Iter59, Testing Accuracy:0.9179\n",
      "Iter60, Testing Accuracy:0.9176\n",
      "Iter61, Testing Accuracy:0.9181\n",
      "Iter62, Testing Accuracy:0.9181\n",
      "Iter63, Testing Accuracy:0.9178\n",
      "Iter64, Testing Accuracy:0.9183\n",
      "Iter65, Testing Accuracy:0.9186\n",
      "Iter66, Testing Accuracy:0.9181\n",
      "Iter67, Testing Accuracy:0.9183\n",
      "Iter68, Testing Accuracy:0.9185\n",
      "Iter69, Testing Accuracy:0.9181\n",
      "Iter70, Testing Accuracy:0.9188\n",
      "Iter71, Testing Accuracy:0.9187\n",
      "Iter72, Testing Accuracy:0.9187\n",
      "Iter73, Testing Accuracy:0.9185\n",
      "Iter74, Testing Accuracy:0.919\n",
      "Iter75, Testing Accuracy:0.9189\n",
      "Iter76, Testing Accuracy:0.919\n",
      "Iter77, Testing Accuracy:0.9198\n",
      "Iter78, Testing Accuracy:0.9193\n",
      "Iter79, Testing Accuracy:0.9192\n",
      "Iter80, Testing Accuracy:0.9193\n",
      "Iter81, Testing Accuracy:0.9198\n",
      "Iter82, Testing Accuracy:0.9196\n",
      "Iter83, Testing Accuracy:0.92\n",
      "Iter84, Testing Accuracy:0.9202\n",
      "Iter85, Testing Accuracy:0.9201\n",
      "Iter86, Testing Accuracy:0.9203\n",
      "Iter87, Testing Accuracy:0.9202\n",
      "Iter88, Testing Accuracy:0.9206\n",
      "Iter89, Testing Accuracy:0.9204\n",
      "Iter90, Testing Accuracy:0.9204\n",
      "Iter91, Testing Accuracy:0.9207\n",
      "Iter92, Testing Accuracy:0.921\n",
      "Iter93, Testing Accuracy:0.9208\n",
      "Iter94, Testing Accuracy:0.9212\n",
      "Iter95, Testing Accuracy:0.9216\n",
      "Iter96, Testing Accuracy:0.9212\n",
      "Iter97, Testing Accuracy:0.9213\n",
      "Iter98, Testing Accuracy:0.9211\n",
      "Iter99, Testing Accuracy:0.9212\n",
      "Iter100, Testing Accuracy:0.9213\n",
      "Iter101, Testing Accuracy:0.9215\n",
      "Iter102, Testing Accuracy:0.9214\n",
      "Iter103, Testing Accuracy:0.9218\n",
      "Iter104, Testing Accuracy:0.9214\n",
      "Iter105, Testing Accuracy:0.9219\n",
      "Iter106, Testing Accuracy:0.9216\n",
      "Iter107, Testing Accuracy:0.9218\n",
      "Iter108, Testing Accuracy:0.9217\n",
      "Iter109, Testing Accuracy:0.922\n",
      "Iter110, Testing Accuracy:0.9223\n",
      "Iter111, Testing Accuracy:0.9224\n",
      "Iter112, Testing Accuracy:0.9222\n",
      "Iter113, Testing Accuracy:0.9224\n",
      "Iter114, Testing Accuracy:0.9221\n",
      "Iter115, Testing Accuracy:0.9224\n",
      "Iter116, Testing Accuracy:0.9225\n",
      "Iter117, Testing Accuracy:0.9226\n",
      "Iter118, Testing Accuracy:0.9228\n",
      "Iter119, Testing Accuracy:0.9224\n",
      "Iter120, Testing Accuracy:0.9224\n",
      "Iter121, Testing Accuracy:0.923\n",
      "Iter122, Testing Accuracy:0.9228\n",
      "Iter123, Testing Accuracy:0.9233\n",
      "Iter124, Testing Accuracy:0.9233\n",
      "Iter125, Testing Accuracy:0.9231\n",
      "Iter126, Testing Accuracy:0.9232\n",
      "Iter127, Testing Accuracy:0.9234\n",
      "Iter128, Testing Accuracy:0.9234\n",
      "Iter129, Testing Accuracy:0.9234\n",
      "Iter130, Testing Accuracy:0.9235\n",
      "Iter131, Testing Accuracy:0.9234\n",
      "Iter132, Testing Accuracy:0.9235\n",
      "Iter133, Testing Accuracy:0.924\n",
      "Iter134, Testing Accuracy:0.9235\n",
      "Iter135, Testing Accuracy:0.9238\n",
      "Iter136, Testing Accuracy:0.9238\n",
      "Iter137, Testing Accuracy:0.9238\n",
      "Iter138, Testing Accuracy:0.9238\n",
      "Iter139, Testing Accuracy:0.9243\n",
      "Iter140, Testing Accuracy:0.924\n",
      "Iter141, Testing Accuracy:0.9242\n",
      "Iter142, Testing Accuracy:0.924\n",
      "Iter143, Testing Accuracy:0.9239\n",
      "Iter144, Testing Accuracy:0.9242\n",
      "Iter145, Testing Accuracy:0.924\n",
      "Iter146, Testing Accuracy:0.9247\n",
      "Iter147, Testing Accuracy:0.9244\n",
      "Iter148, Testing Accuracy:0.9241\n",
      "Iter149, Testing Accuracy:0.9243\n",
      "Iter150, Testing Accuracy:0.9245\n",
      "Iter151, Testing Accuracy:0.9243\n",
      "Iter152, Testing Accuracy:0.9246\n",
      "Iter153, Testing Accuracy:0.9247\n",
      "Iter154, Testing Accuracy:0.9246\n",
      "Iter155, Testing Accuracy:0.9247\n",
      "Iter156, Testing Accuracy:0.9249\n",
      "Iter157, Testing Accuracy:0.9246\n",
      "Iter158, Testing Accuracy:0.9246\n",
      "Iter159, Testing Accuracy:0.9252\n",
      "Iter160, Testing Accuracy:0.9251\n",
      "Iter161, Testing Accuracy:0.9247\n",
      "Iter162, Testing Accuracy:0.9245\n",
      "Iter163, Testing Accuracy:0.925\n",
      "Iter164, Testing Accuracy:0.9247\n",
      "Iter165, Testing Accuracy:0.9253\n",
      "Iter166, Testing Accuracy:0.9248\n",
      "Iter167, Testing Accuracy:0.9251\n",
      "Iter168, Testing Accuracy:0.9251\n",
      "Iter169, Testing Accuracy:0.9256\n",
      "Iter170, Testing Accuracy:0.9251\n",
      "Iter171, Testing Accuracy:0.925\n",
      "Iter172, Testing Accuracy:0.9255\n",
      "Iter173, Testing Accuracy:0.9253\n",
      "Iter174, Testing Accuracy:0.9255\n",
      "Iter175, Testing Accuracy:0.9251\n",
      "Iter176, Testing Accuracy:0.9254\n",
      "Iter177, Testing Accuracy:0.9258\n",
      "Iter178, Testing Accuracy:0.9254\n",
      "Iter179, Testing Accuracy:0.9257\n",
      "Iter180, Testing Accuracy:0.9257\n",
      "Iter181, Testing Accuracy:0.9257\n",
      "Iter182, Testing Accuracy:0.9257\n",
      "Iter183, Testing Accuracy:0.9258\n",
      "Iter184, Testing Accuracy:0.9259\n",
      "Iter185, Testing Accuracy:0.926\n",
      "Iter186, Testing Accuracy:0.9259\n",
      "Iter187, Testing Accuracy:0.9257\n",
      "Iter188, Testing Accuracy:0.9257\n",
      "Iter189, Testing Accuracy:0.926\n",
      "Iter190, Testing Accuracy:0.9257\n",
      "Iter191, Testing Accuracy:0.9258\n",
      "Iter192, Testing Accuracy:0.926\n",
      "Iter193, Testing Accuracy:0.9261\n",
      "Iter194, Testing Accuracy:0.926\n",
      "Iter195, Testing Accuracy:0.9257\n",
      "Iter196, Testing Accuracy:0.9261\n",
      "Iter197, Testing Accuracy:0.9261\n",
      "Iter198, Testing Accuracy:0.926\n",
      "Iter199, Testing Accuracy:0.9259\n",
      "Iter200, Testing Accuracy:0.9265\n",
      "Iter201, Testing Accuracy:0.9263\n",
      "Iter202, Testing Accuracy:0.9265\n",
      "Iter203, Testing Accuracy:0.9259\n",
      "Iter204, Testing Accuracy:0.9261\n",
      "Iter205, Testing Accuracy:0.9262\n",
      "Iter206, Testing Accuracy:0.9263\n",
      "Iter207, Testing Accuracy:0.9266\n",
      "Iter208, Testing Accuracy:0.9265\n",
      "Iter209, Testing Accuracy:0.9266\n",
      "Iter210, Testing Accuracy:0.9267\n",
      "Iter211, Testing Accuracy:0.926\n",
      "Iter212, Testing Accuracy:0.9262\n",
      "Iter213, Testing Accuracy:0.9265\n",
      "Iter214, Testing Accuracy:0.9266\n",
      "Iter215, Testing Accuracy:0.9264\n",
      "Iter216, Testing Accuracy:0.9268\n",
      "Iter217, Testing Accuracy:0.9266\n",
      "Iter218, Testing Accuracy:0.9263\n",
      "Iter219, Testing Accuracy:0.9269\n",
      "Iter220, Testing Accuracy:0.9269\n",
      "Iter221, Testing Accuracy:0.927\n",
      "Iter222, Testing Accuracy:0.927\n",
      "Iter223, Testing Accuracy:0.9265\n",
      "Iter224, Testing Accuracy:0.9265\n",
      "Iter225, Testing Accuracy:0.9266\n",
      "Iter226, Testing Accuracy:0.9268\n",
      "Iter227, Testing Accuracy:0.9269\n",
      "Iter228, Testing Accuracy:0.9264\n",
      "Iter229, Testing Accuracy:0.927\n",
      "Iter230, Testing Accuracy:0.9266\n",
      "Iter231, Testing Accuracy:0.927\n",
      "Iter232, Testing Accuracy:0.9269\n",
      "Iter233, Testing Accuracy:0.9271\n",
      "Iter234, Testing Accuracy:0.9275\n",
      "Iter235, Testing Accuracy:0.927\n",
      "Iter236, Testing Accuracy:0.9269\n",
      "Iter237, Testing Accuracy:0.9271\n",
      "Iter238, Testing Accuracy:0.927\n",
      "Iter239, Testing Accuracy:0.9272\n",
      "Iter240, Testing Accuracy:0.927\n",
      "Iter241, Testing Accuracy:0.9269\n",
      "Iter242, Testing Accuracy:0.9268\n",
      "Iter243, Testing Accuracy:0.9269\n",
      "Iter244, Testing Accuracy:0.9278\n",
      "Iter245, Testing Accuracy:0.9274\n",
      "Iter246, Testing Accuracy:0.9274\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Iter247, Testing Accuracy:0.9275\n",
      "Iter248, Testing Accuracy:0.9272\n",
      "Iter249, Testing Accuracy:0.9274\n",
      "Iter250, Testing Accuracy:0.9276\n",
      "Iter251, Testing Accuracy:0.9277\n",
      "Iter252, Testing Accuracy:0.927\n",
      "Iter253, Testing Accuracy:0.9272\n",
      "Iter254, Testing Accuracy:0.9269\n",
      "Iter255, Testing Accuracy:0.9277\n",
      "Iter256, Testing Accuracy:0.9275\n",
      "Iter257, Testing Accuracy:0.928\n",
      "Iter258, Testing Accuracy:0.9272\n",
      "Iter259, Testing Accuracy:0.9279\n",
      "Iter260, Testing Accuracy:0.9274\n",
      "Iter261, Testing Accuracy:0.9273\n",
      "Iter262, Testing Accuracy:0.9273\n",
      "Iter263, Testing Accuracy:0.9272\n",
      "Iter264, Testing Accuracy:0.9281\n",
      "Iter265, Testing Accuracy:0.9277\n",
      "Iter266, Testing Accuracy:0.9277\n",
      "Iter267, Testing Accuracy:0.9275\n",
      "Iter268, Testing Accuracy:0.9278\n",
      "Iter269, Testing Accuracy:0.9279\n",
      "Iter270, Testing Accuracy:0.9282\n",
      "Iter271, Testing Accuracy:0.9279\n",
      "Iter272, Testing Accuracy:0.928\n",
      "Iter273, Testing Accuracy:0.9282\n",
      "Iter274, Testing Accuracy:0.9284\n",
      "Iter275, Testing Accuracy:0.9283\n",
      "Iter276, Testing Accuracy:0.9282\n",
      "Iter277, Testing Accuracy:0.9287\n",
      "Iter278, Testing Accuracy:0.9283\n",
      "Iter279, Testing Accuracy:0.9282\n",
      "Iter280, Testing Accuracy:0.9277\n",
      "Iter281, Testing Accuracy:0.9283\n",
      "Iter282, Testing Accuracy:0.9283\n",
      "Iter283, Testing Accuracy:0.9281\n",
      "Iter284, Testing Accuracy:0.9284\n",
      "Iter285, Testing Accuracy:0.9282\n",
      "Iter286, Testing Accuracy:0.9285\n",
      "Iter287, Testing Accuracy:0.928\n",
      "Iter288, Testing Accuracy:0.9284\n",
      "Iter289, Testing Accuracy:0.9282\n",
      "Iter290, Testing Accuracy:0.9286\n",
      "Iter291, Testing Accuracy:0.9284\n",
      "Iter292, Testing Accuracy:0.9284\n",
      "Iter293, Testing Accuracy:0.9284\n",
      "Iter294, Testing Accuracy:0.9281\n",
      "Iter295, Testing Accuracy:0.9287\n",
      "Iter296, Testing Accuracy:0.9285\n",
      "Iter297, Testing Accuracy:0.9287\n",
      "Iter298, Testing Accuracy:0.9277\n",
      "Iter299, Testing Accuracy:0.9288\n",
      "Iter300, Testing Accuracy:0.9284\n",
      "Iter301, Testing Accuracy:0.9287\n",
      "Iter302, Testing Accuracy:0.9286\n",
      "Iter303, Testing Accuracy:0.9287\n",
      "Iter304, Testing Accuracy:0.9284\n",
      "Iter305, Testing Accuracy:0.9289\n",
      "Iter306, Testing Accuracy:0.9281\n",
      "Iter307, Testing Accuracy:0.9284\n",
      "Iter308, Testing Accuracy:0.9288\n",
      "Iter309, Testing Accuracy:0.9287\n",
      "Iter310, Testing Accuracy:0.9286\n",
      "Iter311, Testing Accuracy:0.9286\n",
      "Iter312, Testing Accuracy:0.9288\n",
      "Iter313, Testing Accuracy:0.929\n",
      "Iter314, Testing Accuracy:0.9291\n",
      "Iter315, Testing Accuracy:0.929\n",
      "Iter316, Testing Accuracy:0.929\n",
      "Iter317, Testing Accuracy:0.929\n",
      "Iter318, Testing Accuracy:0.9287\n",
      "Iter319, Testing Accuracy:0.929\n",
      "Iter320, Testing Accuracy:0.9289\n",
      "Iter321, Testing Accuracy:0.9292\n",
      "Iter322, Testing Accuracy:0.9289\n",
      "Iter323, Testing Accuracy:0.9291\n",
      "Iter324, Testing Accuracy:0.9291\n",
      "Iter325, Testing Accuracy:0.9289\n",
      "Iter326, Testing Accuracy:0.9291\n",
      "Iter327, Testing Accuracy:0.9289\n",
      "Iter328, Testing Accuracy:0.9288\n",
      "Iter329, Testing Accuracy:0.929\n",
      "Iter330, Testing Accuracy:0.9292\n",
      "Iter331, Testing Accuracy:0.9289\n",
      "Iter332, Testing Accuracy:0.929\n",
      "Iter333, Testing Accuracy:0.929\n",
      "Iter334, Testing Accuracy:0.9289\n",
      "Iter335, Testing Accuracy:0.9288\n",
      "Iter336, Testing Accuracy:0.929\n",
      "Iter337, Testing Accuracy:0.9288\n",
      "Iter338, Testing Accuracy:0.9287\n",
      "Iter339, Testing Accuracy:0.929\n",
      "Iter340, Testing Accuracy:0.9291\n",
      "Iter341, Testing Accuracy:0.9289\n",
      "Iter342, Testing Accuracy:0.9289\n",
      "Iter343, Testing Accuracy:0.9286\n",
      "Iter344, Testing Accuracy:0.9291\n",
      "Iter345, Testing Accuracy:0.9291\n",
      "Iter346, Testing Accuracy:0.9291\n",
      "Iter347, Testing Accuracy:0.9288\n",
      "Iter348, Testing Accuracy:0.9292\n",
      "Iter349, Testing Accuracy:0.9291\n",
      "Iter350, Testing Accuracy:0.929\n",
      "Iter351, Testing Accuracy:0.929\n",
      "Iter352, Testing Accuracy:0.929\n",
      "Iter353, Testing Accuracy:0.929\n",
      "Iter354, Testing Accuracy:0.9289\n",
      "Iter355, Testing Accuracy:0.9291\n",
      "Iter356, Testing Accuracy:0.9291\n",
      "Iter357, Testing Accuracy:0.9291\n",
      "Iter358, Testing Accuracy:0.9291\n",
      "Iter359, Testing Accuracy:0.9291\n",
      "Iter360, Testing Accuracy:0.929\n",
      "Iter361, Testing Accuracy:0.929\n",
      "Iter362, Testing Accuracy:0.929\n",
      "Iter363, Testing Accuracy:0.9289\n",
      "Iter364, Testing Accuracy:0.9288\n",
      "Iter365, Testing Accuracy:0.929\n",
      "Iter366, Testing Accuracy:0.9291\n",
      "Iter367, Testing Accuracy:0.929\n",
      "Iter368, Testing Accuracy:0.9289\n",
      "Iter369, Testing Accuracy:0.929\n",
      "Iter370, Testing Accuracy:0.9292\n",
      "Iter371, Testing Accuracy:0.9289\n",
      "Iter372, Testing Accuracy:0.9291\n",
      "Iter373, Testing Accuracy:0.929\n",
      "Iter374, Testing Accuracy:0.9291\n",
      "Iter375, Testing Accuracy:0.9288\n",
      "Iter376, Testing Accuracy:0.9291\n",
      "Iter377, Testing Accuracy:0.9289\n",
      "Iter378, Testing Accuracy:0.9289\n",
      "Iter379, Testing Accuracy:0.9292\n",
      "Iter380, Testing Accuracy:0.9293\n",
      "Iter381, Testing Accuracy:0.9291\n",
      "Iter382, Testing Accuracy:0.9291\n",
      "Iter383, Testing Accuracy:0.9291\n",
      "Iter384, Testing Accuracy:0.9289\n",
      "Iter385, Testing Accuracy:0.9287\n",
      "Iter386, Testing Accuracy:0.929\n",
      "Iter387, Testing Accuracy:0.929\n",
      "Iter388, Testing Accuracy:0.9291\n",
      "Iter389, Testing Accuracy:0.9289\n",
      "Iter390, Testing Accuracy:0.9291\n",
      "Iter391, Testing Accuracy:0.929\n",
      "Iter392, Testing Accuracy:0.929\n",
      "Iter393, Testing Accuracy:0.929\n",
      "Iter394, Testing Accuracy:0.929\n",
      "Iter395, Testing Accuracy:0.929\n",
      "Iter396, Testing Accuracy:0.9288\n",
      "Iter397, Testing Accuracy:0.9292\n",
      "Iter398, Testing Accuracy:0.9286\n",
      "Iter399, Testing Accuracy:0.929\n",
      "Iter400, Testing Accuracy:0.9289\n",
      "Iter401, Testing Accuracy:0.9289\n",
      "Iter402, Testing Accuracy:0.929\n",
      "Iter403, Testing Accuracy:0.929\n",
      "Iter404, Testing Accuracy:0.9288\n",
      "Iter405, Testing Accuracy:0.9289\n",
      "Iter406, Testing Accuracy:0.9287\n",
      "Iter407, Testing Accuracy:0.929\n",
      "Iter408, Testing Accuracy:0.929\n",
      "Iter409, Testing Accuracy:0.9289\n",
      "Iter410, Testing Accuracy:0.929\n",
      "Iter411, Testing Accuracy:0.9289\n",
      "Iter412, Testing Accuracy:0.9288\n",
      "Iter413, Testing Accuracy:0.929\n",
      "Iter414, Testing Accuracy:0.9288\n",
      "Iter415, Testing Accuracy:0.929\n",
      "Iter416, Testing Accuracy:0.9288\n",
      "Iter417, Testing Accuracy:0.9292\n",
      "Iter418, Testing Accuracy:0.929\n",
      "Iter419, Testing Accuracy:0.9292\n",
      "Iter420, Testing Accuracy:0.9293\n",
      "Iter421, Testing Accuracy:0.9293\n",
      "Iter422, Testing Accuracy:0.9293\n",
      "Iter423, Testing Accuracy:0.929\n",
      "Iter424, Testing Accuracy:0.9292\n",
      "Iter425, Testing Accuracy:0.929\n",
      "Iter426, Testing Accuracy:0.9291\n",
      "Iter427, Testing Accuracy:0.929\n",
      "Iter428, Testing Accuracy:0.929\n",
      "Iter429, Testing Accuracy:0.929\n",
      "Iter430, Testing Accuracy:0.9292\n",
      "Iter431, Testing Accuracy:0.9292\n",
      "Iter432, Testing Accuracy:0.9295\n",
      "Iter433, Testing Accuracy:0.9291\n",
      "Iter434, Testing Accuracy:0.9292\n",
      "Iter435, Testing Accuracy:0.9293\n",
      "Iter436, Testing Accuracy:0.9292\n",
      "Iter437, Testing Accuracy:0.929\n",
      "Iter438, Testing Accuracy:0.9293\n",
      "Iter439, Testing Accuracy:0.9291\n",
      "Iter440, Testing Accuracy:0.9291\n",
      "Iter441, Testing Accuracy:0.9295\n",
      "Iter442, Testing Accuracy:0.9295\n",
      "Iter443, Testing Accuracy:0.9289\n",
      "Iter444, Testing Accuracy:0.9294\n",
      "Iter445, Testing Accuracy:0.9293\n",
      "Iter446, Testing Accuracy:0.9292\n",
      "Iter447, Testing Accuracy:0.9294\n",
      "Iter448, Testing Accuracy:0.9294\n",
      "Iter449, Testing Accuracy:0.9297\n",
      "Iter450, Testing Accuracy:0.9295\n",
      "Iter451, Testing Accuracy:0.9294\n",
      "Iter452, Testing Accuracy:0.9295\n",
      "Iter453, Testing Accuracy:0.9294\n",
      "Iter454, Testing Accuracy:0.9293\n",
      "Iter455, Testing Accuracy:0.9292\n",
      "Iter456, Testing Accuracy:0.9293\n",
      "Iter457, Testing Accuracy:0.9294\n",
      "Iter458, Testing Accuracy:0.9293\n",
      "Iter459, Testing Accuracy:0.9294\n",
      "Iter460, Testing Accuracy:0.9292\n",
      "Iter461, Testing Accuracy:0.9293\n",
      "Iter462, Testing Accuracy:0.9292\n",
      "Iter463, Testing Accuracy:0.9295\n",
      "Iter464, Testing Accuracy:0.9294\n",
      "Iter465, Testing Accuracy:0.9294\n",
      "Iter466, Testing Accuracy:0.9294\n",
      "Iter467, Testing Accuracy:0.9295\n",
      "Iter468, Testing Accuracy:0.9294\n",
      "Iter469, Testing Accuracy:0.9292\n",
      "Iter470, Testing Accuracy:0.9294\n",
      "Iter471, Testing Accuracy:0.9295\n",
      "Iter472, Testing Accuracy:0.9293\n",
      "Iter473, Testing Accuracy:0.9294\n",
      "Iter474, Testing Accuracy:0.9296\n",
      "Iter475, Testing Accuracy:0.9295\n",
      "Iter476, Testing Accuracy:0.9298\n",
      "Iter477, Testing Accuracy:0.9296\n",
      "Iter478, Testing Accuracy:0.9291\n",
      "Iter479, Testing Accuracy:0.9292\n",
      "Iter480, Testing Accuracy:0.9293\n",
      "Iter481, Testing Accuracy:0.9291\n",
      "Iter482, Testing Accuracy:0.9295\n",
      "Iter483, Testing Accuracy:0.9296\n",
      "Iter484, Testing Accuracy:0.9296\n",
      "Iter485, Testing Accuracy:0.9294\n",
      "Iter486, Testing Accuracy:0.9294\n",
      "Iter487, Testing Accuracy:0.9292\n",
      "Iter488, Testing Accuracy:0.9294\n",
      "Iter489, Testing Accuracy:0.9292\n",
      "Iter490, Testing Accuracy:0.9294\n",
      "Iter491, Testing Accuracy:0.9293\n",
      "Iter492, Testing Accuracy:0.9295\n",
      "Iter493, Testing Accuracy:0.9294\n",
      "Iter494, Testing Accuracy:0.9296\n",
      "Iter495, Testing Accuracy:0.9294\n",
      "Iter496, Testing Accuracy:0.9295\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Iter497, Testing Accuracy:0.9295\n",
      "Iter498, Testing Accuracy:0.9294\n",
      "Iter499, Testing Accuracy:0.9295\n",
      "completed\n"
     ]
    }
   ],
   "source": [
    "# 载入数据集\n",
    "mnist=input_data.read_data_sets(\"MNIST_data\",one_hot=True)\n",
    "\n",
    "# 每个批次的大小\n",
    "batch_size=200 # 每次放入的数据量\n",
    "# 计算有多少个批次\n",
    "n_batch=mnist.train.num_examples // batch_size\n",
    "\n",
    "# 定义两个placeholder\n",
    "x=tf.placeholder(tf.float32,[None,784])\n",
    "y=tf.placeholder(tf.float32,[None,10])\n",
    "\n",
    "# 创建简单的神经网络\n",
    "W=tf.Variable(tf.zeros([784,10]))\n",
    "b=tf.Variable(tf.zeros([10]))\n",
    "prediction=tf.nn.softmax(tf.matmul(x,W)+b)\n",
    "\n",
    "# 二次代价函数\n",
    "loss=tf.reduce_mean(tf.square(y-prediction))\n",
    "# 使用梯度下降法\n",
    "train_step=tf.train.GradientDescentOptimizer(0.2).minimize(loss)\n",
    "\n",
    "# 记过存放在布尔型列表中\n",
    "correct_prediction=tf.equal(tf.argmax(y,1),tf.argmax(prediction,1)) # 最大值所在位置\n",
    "# 求准确率\n",
    "accuracy=tf.reduce_mean(tf.cast(correct_prediction,tf.float32))\n",
    "\n",
    "with tf.Session() as sess:\n",
    "    sess.run(tf.global_variables_initializer())\n",
    "    for epoch in range(500):\n",
    "        for batch in range(n_batch):\n",
    "            batch_xs,batch_ys=mnist.train.next_batch(batch_size)\n",
    "            sess.run(train_step,feed_dict={x:batch_xs,y:batch_ys})\n",
    "        \n",
    "        acc=sess.run(accuracy,feed_dict={x:mnist.test.images,y:mnist.test.labels})\n",
    "        print(\"Iter\"+str(epoch)+\", Testing Accuracy:\"+str(acc))\n",
    "\n",
    "print('completed')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 尝试多层感知机进行测试\n",
    "结果似乎并不能行得通"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Extracting MNIST_data\\train-images-idx3-ubyte.gz\n",
      "Extracting MNIST_data\\train-labels-idx1-ubyte.gz\n",
      "Extracting MNIST_data\\t10k-images-idx3-ubyte.gz\n",
      "Extracting MNIST_data\\t10k-labels-idx1-ubyte.gz\n",
      "Iter 0, Testing Accuracy:0.0833\n",
      "Iter 10, Testing Accuracy:0.1406\n",
      "Iter 20, Testing Accuracy:0.1913\n",
      "Iter 30, Testing Accuracy:0.2364\n",
      "Iter 40, Testing Accuracy:0.2731\n",
      "Iter 50, Testing Accuracy:0.3099\n",
      "Iter 60, Testing Accuracy:0.3364\n",
      "Iter 70, Testing Accuracy:0.3616\n",
      "Iter 80, Testing Accuracy:0.3869\n",
      "Iter 90, Testing Accuracy:0.408\n",
      "Iter 100, Testing Accuracy:0.4318\n",
      "Iter 110, Testing Accuracy:0.4554\n",
      "Iter 120, Testing Accuracy:0.4716\n",
      "Iter 130, Testing Accuracy:0.4876\n",
      "Iter 140, Testing Accuracy:0.5002\n",
      "Iter 150, Testing Accuracy:0.5166\n",
      "Iter 160, Testing Accuracy:0.5368\n",
      "Iter 170, Testing Accuracy:0.5485\n",
      "Iter 180, Testing Accuracy:0.5588\n",
      "Iter 190, Testing Accuracy:0.5682\n",
      "Iter 200, Testing Accuracy:0.5782\n",
      "Iter 210, Testing Accuracy:0.5874\n",
      "Iter 220, Testing Accuracy:0.5953\n",
      "Iter 230, Testing Accuracy:0.6019\n",
      "Iter 240, Testing Accuracy:0.6066\n",
      "Iter 250, Testing Accuracy:0.6141\n",
      "Iter 260, Testing Accuracy:0.6218\n",
      "Iter 270, Testing Accuracy:0.6279\n",
      "Iter 280, Testing Accuracy:0.6343\n",
      "Iter 290, Testing Accuracy:0.6389\n",
      "Iter 300, Testing Accuracy:0.6442\n",
      "Iter 310, Testing Accuracy:0.6504\n",
      "Iter 320, Testing Accuracy:0.6552\n",
      "Iter 330, Testing Accuracy:0.661\n",
      "Iter 340, Testing Accuracy:0.6664\n",
      "Iter 350, Testing Accuracy:0.6714\n",
      "Iter 360, Testing Accuracy:0.6754\n",
      "Iter 370, Testing Accuracy:0.678\n",
      "Iter 380, Testing Accuracy:0.6813\n",
      "Iter 390, Testing Accuracy:0.6833\n",
      "Iter 400, Testing Accuracy:0.6874\n",
      "Iter 410, Testing Accuracy:0.6908\n",
      "Iter 420, Testing Accuracy:0.6924\n",
      "Iter 430, Testing Accuracy:0.6941\n",
      "Iter 440, Testing Accuracy:0.6966\n",
      "Iter 450, Testing Accuracy:0.699\n",
      "Iter 460, Testing Accuracy:0.7022\n",
      "Iter 470, Testing Accuracy:0.7059\n",
      "Iter 480, Testing Accuracy:0.7066\n",
      "Iter 490, Testing Accuracy:0.7078\n",
      "Iter 500, Testing Accuracy:0.7099\n",
      "completed\n"
     ]
    }
   ],
   "source": [
    "# 载入数据集\n",
    "mnist=input_data.read_data_sets(\"MNIST_data\",one_hot=True)\n",
    "\n",
    "# 每个批次的大小\n",
    "batch_size=100 # 每次放入的数据量\n",
    "# 计算有多少个批次\n",
    "n_batch=mnist.train.num_examples // batch_size\n",
    "\n",
    "# 定义两个placeholder\n",
    "x=tf.placeholder(tf.float32,[None,784])\n",
    "y=tf.placeholder(tf.float32,[None,10])\n",
    "\n",
    "# 创建简单的神经网络（第一层）\n",
    "Weights_L1=tf.Variable(tf.random_normal([784,512]))\n",
    "biases_L1=tf.Variable(tf.zeros([512]))\n",
    "Wx_plus_b_L1=tf.matmul(x,Weights_L1)+biases_L1\n",
    "L1=tf.nn.tanh(Wx_plus_b_L1)\n",
    "\n",
    "# 创建简单的神经网络（第二层）\n",
    "Weights_L2=tf.Variable(tf.random_normal([512,10]))\n",
    "biases_L2=tf.Variable(tf.zeros([10]))\n",
    "Wx_plus_b_L2=tf.matmul(L1,Weights_L2)+biases_L2\n",
    "L2=tf.nn.tanh(Wx_plus_b_L2)\n",
    "\n",
    "# 创建简单的神经网络（第三层）\n",
    "Weights_L3=tf.Variable(tf.random_normal([10,10]))\n",
    "biases_L3=tf.Variable(tf.zeros([10]))\n",
    "prediction=tf.nn.softmax(tf.matmul(L2,Weights_L3)+biases_L3)\n",
    "\n",
    "# 二次代价函数\n",
    "loss=tf.reduce_mean(tf.square(y-prediction))\n",
    "# 使用梯度下降法\n",
    "train_step=tf.train.GradientDescentOptimizer(0.02).minimize(loss)\n",
    "\n",
    "# 记过存放在布尔型列表中\n",
    "correct_prediction=tf.equal(tf.argmax(y,1),tf.argmax(prediction,1)) # 最大值所在位置\n",
    "# 求准确率\n",
    "accuracy=tf.reduce_mean(tf.cast(correct_prediction,tf.float32))\n",
    "\n",
    "with tf.Session() as sess:\n",
    "    sess.run(tf.global_variables_initializer())\n",
    "    for epoch in range(501):\n",
    "        for batch in range(n_batch):\n",
    "            batch_xs,batch_ys=mnist.train.next_batch(batch_size)\n",
    "            sess.run(train_step,feed_dict={x:batch_xs,y:batch_ys})\n",
    "        \n",
    "        acc=sess.run(accuracy,feed_dict={x:mnist.test.images,y:mnist.test.labels})\n",
    "        if(epoch%10==0):\n",
    "            print(\"Iter \"+str(epoch)+\", Testing Accuracy:\"+str(acc))\n",
    "\n",
    "print('completed')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Extracting MNIST_data\\train-images-idx3-ubyte.gz\n",
      "Extracting MNIST_data\\train-labels-idx1-ubyte.gz\n",
      "Extracting MNIST_data\\t10k-images-idx3-ubyte.gz\n",
      "Extracting MNIST_data\\t10k-labels-idx1-ubyte.gz\n",
      "Iter 0, Testing Accuracy:0.1461\n",
      "Iter 20, Testing Accuracy:0.5171\n",
      "Iter 40, Testing Accuracy:0.5473\n",
      "Iter 60, Testing Accuracy:0.584\n",
      "Iter 80, Testing Accuracy:0.6103\n",
      "Iter 100, Testing Accuracy:0.6242\n",
      "Iter 120, Testing Accuracy:0.6298\n",
      "Iter 140, Testing Accuracy:0.6347\n",
      "Iter 160, Testing Accuracy:0.6395\n",
      "Iter 180, Testing Accuracy:0.6435\n",
      "Iter 200, Testing Accuracy:0.6773\n",
      "Iter 220, Testing Accuracy:0.7133\n",
      "Iter 240, Testing Accuracy:0.7225\n",
      "Iter 260, Testing Accuracy:0.7313\n",
      "Iter 280, Testing Accuracy:0.7355\n",
      "Iter 300, Testing Accuracy:0.7369\n",
      "Iter 320, Testing Accuracy:0.7404\n",
      "Iter 340, Testing Accuracy:0.7425\n",
      "Iter 360, Testing Accuracy:0.742\n",
      "Iter 380, Testing Accuracy:0.7448\n",
      "Iter 400, Testing Accuracy:0.7455\n",
      "Iter 420, Testing Accuracy:0.746\n",
      "Iter 440, Testing Accuracy:0.7462\n",
      "Iter 460, Testing Accuracy:0.7506\n",
      "Iter 480, Testing Accuracy:0.7498\n",
      "Iter 500, Testing Accuracy:0.751\n",
      "Iter 520, Testing Accuracy:0.7537\n",
      "Iter 540, Testing Accuracy:0.7532\n",
      "Iter 560, Testing Accuracy:0.7544\n",
      "Iter 580, Testing Accuracy:0.7561\n",
      "Iter 600, Testing Accuracy:0.7532\n",
      "Iter 620, Testing Accuracy:0.7555\n",
      "Iter 640, Testing Accuracy:0.7556\n",
      "Iter 660, Testing Accuracy:0.7561\n",
      "Iter 680, Testing Accuracy:0.7576\n",
      "Iter 700, Testing Accuracy:0.7548\n",
      "Iter 720, Testing Accuracy:0.7576\n",
      "Iter 740, Testing Accuracy:0.7602\n",
      "Iter 760, Testing Accuracy:0.7615\n",
      "Iter 780, Testing Accuracy:0.7586\n",
      "Iter 800, Testing Accuracy:0.7613\n",
      "Iter 820, Testing Accuracy:0.7601\n",
      "Iter 840, Testing Accuracy:0.7607\n",
      "Iter 860, Testing Accuracy:0.7605\n",
      "Iter 880, Testing Accuracy:0.7595\n",
      "Iter 900, Testing Accuracy:0.7624\n",
      "Iter 920, Testing Accuracy:0.7645\n",
      "Iter 940, Testing Accuracy:0.7636\n",
      "Iter 960, Testing Accuracy:0.7618\n",
      "Iter 980, Testing Accuracy:0.7625\n",
      "Iter 1000, Testing Accuracy:0.7634\n",
      "Iter 1020, Testing Accuracy:0.763\n",
      "Iter 1040, Testing Accuracy:0.7628\n",
      "Iter 1060, Testing Accuracy:0.7644\n",
      "Iter 1080, Testing Accuracy:0.7633\n",
      "Iter 1100, Testing Accuracy:0.7646\n",
      "Iter 1120, Testing Accuracy:0.7656\n",
      "Iter 1140, Testing Accuracy:0.7655\n",
      "Iter 1160, Testing Accuracy:0.7645\n",
      "Iter 1180, Testing Accuracy:0.7632\n",
      "Iter 1200, Testing Accuracy:0.7652\n",
      "Iter 1220, Testing Accuracy:0.7671\n",
      "Iter 1240, Testing Accuracy:0.7656\n",
      "Iter 1260, Testing Accuracy:0.765\n",
      "Iter 1280, Testing Accuracy:0.7656\n",
      "Iter 1300, Testing Accuracy:0.7647\n",
      "Iter 1320, Testing Accuracy:0.7672\n",
      "Iter 1340, Testing Accuracy:0.7658\n",
      "Iter 1360, Testing Accuracy:0.766\n",
      "Iter 1380, Testing Accuracy:0.7662\n",
      "Iter 1400, Testing Accuracy:0.8376\n",
      "Iter 1420, Testing Accuracy:0.8478\n",
      "Iter 1440, Testing Accuracy:0.8486\n",
      "Iter 1460, Testing Accuracy:0.8508\n",
      "Iter 1480, Testing Accuracy:0.8529\n",
      "Iter 1500, Testing Accuracy:0.8495\n",
      "Iter 1520, Testing Accuracy:0.854\n",
      "Iter 1540, Testing Accuracy:0.8546\n",
      "Iter 1560, Testing Accuracy:0.8535\n",
      "Iter 1580, Testing Accuracy:0.8541\n",
      "Iter 1600, Testing Accuracy:0.8546\n",
      "Iter 1620, Testing Accuracy:0.8549\n",
      "Iter 1640, Testing Accuracy:0.8534\n",
      "Iter 1660, Testing Accuracy:0.8843\n",
      "Iter 1680, Testing Accuracy:0.93\n",
      "Iter 1700, Testing Accuracy:0.9362\n",
      "Iter 1720, Testing Accuracy:0.9391\n",
      "Iter 1740, Testing Accuracy:0.9415\n",
      "Iter 1760, Testing Accuracy:0.9416\n",
      "Iter 1780, Testing Accuracy:0.9456\n",
      "Iter 1800, Testing Accuracy:0.9463\n",
      "Iter 1820, Testing Accuracy:0.9459\n",
      "Iter 1840, Testing Accuracy:0.9474\n",
      "Iter 1860, Testing Accuracy:0.9473\n",
      "Iter 1880, Testing Accuracy:0.9471\n",
      "Iter 1900, Testing Accuracy:0.9485\n",
      "Iter 1920, Testing Accuracy:0.9507\n",
      "Iter 1940, Testing Accuracy:0.9504\n",
      "Iter 1960, Testing Accuracy:0.9495\n",
      "Iter 1980, Testing Accuracy:0.9493\n",
      "Iter 2000, Testing Accuracy:0.9521\n",
      "Iter 2020, Testing Accuracy:0.9521\n",
      "Iter 2040, Testing Accuracy:0.952\n",
      "Iter 2060, Testing Accuracy:0.9522\n",
      "Iter 2080, Testing Accuracy:0.9532\n",
      "Iter 2100, Testing Accuracy:0.9534\n",
      "Iter 2120, Testing Accuracy:0.9506\n",
      "Iter 2140, Testing Accuracy:0.9523\n",
      "Iter 2160, Testing Accuracy:0.9529\n",
      "Iter 2180, Testing Accuracy:0.9535\n",
      "Iter 2200, Testing Accuracy:0.9516\n",
      "Iter 2220, Testing Accuracy:0.9527\n",
      "Iter 2240, Testing Accuracy:0.9526\n",
      "Iter 2260, Testing Accuracy:0.9525\n",
      "Iter 2280, Testing Accuracy:0.9544\n",
      "Iter 2300, Testing Accuracy:0.9559\n",
      "Iter 2320, Testing Accuracy:0.9534\n",
      "Iter 2340, Testing Accuracy:0.956\n",
      "Iter 2360, Testing Accuracy:0.9536\n",
      "Iter 2380, Testing Accuracy:0.9556\n",
      "Iter 2400, Testing Accuracy:0.9561\n",
      "Iter 2420, Testing Accuracy:0.9545\n",
      "Iter 2440, Testing Accuracy:0.9551\n",
      "Iter 2460, Testing Accuracy:0.9552\n",
      "Iter 2480, Testing Accuracy:0.9558\n",
      "Iter 2500, Testing Accuracy:0.9563\n",
      "Iter 2520, Testing Accuracy:0.9563\n",
      "Iter 2540, Testing Accuracy:0.958\n",
      "Iter 2560, Testing Accuracy:0.9574\n",
      "Iter 2580, Testing Accuracy:0.9574\n",
      "Iter 2600, Testing Accuracy:0.9566\n",
      "Iter 2620, Testing Accuracy:0.9579\n",
      "Iter 2640, Testing Accuracy:0.9586\n",
      "Iter 2660, Testing Accuracy:0.9591\n",
      "Iter 2680, Testing Accuracy:0.9593\n",
      "Iter 2700, Testing Accuracy:0.9562\n",
      "Iter 2720, Testing Accuracy:0.9573\n",
      "Iter 2740, Testing Accuracy:0.9593\n",
      "Iter 2760, Testing Accuracy:0.9574\n",
      "Iter 2780, Testing Accuracy:0.9577\n",
      "Iter 2800, Testing Accuracy:0.9601\n",
      "Iter 2820, Testing Accuracy:0.9568\n",
      "Iter 2840, Testing Accuracy:0.9572\n",
      "Iter 2860, Testing Accuracy:0.9583\n",
      "Iter 2880, Testing Accuracy:0.9547\n",
      "Iter 2900, Testing Accuracy:0.9589\n",
      "Iter 2920, Testing Accuracy:0.9586\n",
      "Iter 2940, Testing Accuracy:0.9561\n",
      "Iter 2960, Testing Accuracy:0.9584\n",
      "Iter 2980, Testing Accuracy:0.9591\n",
      "Iter 3000, Testing Accuracy:0.9571\n",
      "completed\n"
     ]
    }
   ],
   "source": [
    "# 载入数据集\n",
    "mnist=input_data.read_data_sets(\"MNIST_data\",one_hot=True)\n",
    "\n",
    "# 每个批次的大小\n",
    "batch_size=200 # 每次放入的数据量\n",
    "# 计算有多少个批次\n",
    "n_batch=mnist.train.num_examples // batch_size\n",
    "\n",
    "# 定义两个placeholder\n",
    "x=tf.placeholder(tf.float32,[None,784])\n",
    "y=tf.placeholder(tf.float32,[None,10])\n",
    "\n",
    "# 创建简单的神经网络（第一层）\n",
    "W1=tf.Variable(tf.random_normal([784,300]))\n",
    "b1=tf.Variable(tf.zeros([300]))\n",
    "L1=tf.nn.relu(tf.matmul(x,W1)+b1)\n",
    "drop_prob=0.75\n",
    "L1=tf.nn.dropout(L1,drop_prob) # 随机失活\n",
    "\n",
    "# 创建简单的蛇精挽留过（第二层）\n",
    "W2=tf.Variable(tf.random_normal([300,10]))\n",
    "b2=tf.Variable(tf.zeros([10]))\n",
    "\n",
    "prediction=tf.nn.softmax(tf.matmul(L1,W2)+b2)\n",
    "\n",
    "# 二次代价函数\n",
    "loss=tf.reduce_mean(tf.square(y-prediction))\n",
    "# loss=tf.reduce_mean(-tf.reduce_sum(y*tf.log(prediction),reduction_indices=[1])) # 用交叉熵\n",
    "# 使用梯度下降法\n",
    "train_step=tf.train.AdagradOptimizer(0.2).minimize(loss)\n",
    "\n",
    "# 记过存放在布尔型列表中\n",
    "correct_prediction=tf.equal(tf.argmax(y,1),tf.argmax(prediction,1)) # 最大值所在位置\n",
    "# 求准确率\n",
    "accuracy=tf.reduce_mean(tf.cast(correct_prediction,tf.float32))\n",
    "\n",
    "with tf.Session() as sess:\n",
    "    sess.run(tf.global_variables_initializer())\n",
    "    for epoch in range(3001):\n",
    "        for batch in range(n_batch):\n",
    "            batch_xs,batch_ys=mnist.train.next_batch(batch_size)\n",
    "            sess.run(train_step,feed_dict={x:batch_xs,y:batch_ys})\n",
    "        \n",
    "        acc=sess.run(accuracy,feed_dict={x:mnist.test.images,y:mnist.test.labels})\n",
    "        \n",
    "        if(epoch%20==0):\n",
    "            print(\"Iter \"+str(epoch)+\", Testing Accuracy:\"+str(acc))\n",
    "\n",
    "print('completed')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
